package com.lazypeople.service.impl;

import com.lazypeople.domain.DownloadTask;
import com.lazypeople.task.impl.HttpDownloadTask;
import com.lazypeople.service.DownloadService;
import java.io.File;

public class HttpDownloadService implements DownloadService {
    @Override
    public DownloadTask createTask(String url, File saveFile, int threadCount) {
        // 参数验证
        if (url == null || url.isEmpty()) {
            throw new IllegalArgumentException("下载URL不能为空");
        }
        if (saveFile == null) {
            throw new IllegalArgumentException("保存文件不能为空");
        }
        if (threadCount <= 0) {
            threadCount = 4; // 默认4线程
        }

        // 创建HTTP下载任务并绑定UI组件
        HttpDownloadTask task = new HttpDownloadTask(url, saveFile, threadCount);

        return task;
    }
}